﻿using System.Data.Entity;
using Modelos;
using System.Data.Entity.ModelConfiguration.Conventions;

namespace SisComercio.Models
{
    public class SisComercioContext : DbContext
    {
        // You can add custom code to this file. Changes will not be overwritten.
        // 
        // If you want Entity Framework to drop and regenerate your database
        // automatically whenever you change your model schema, add the following
        // code to the Application_Start method in your Global.asax file.
        // Note: this will destroy and re-create your database with every model change.
        // 
        // System.Data.Entity.Database.SetInitializer(new System.Data.Entity.DropCreateDatabaseIfModelChanges<SisComercio.Models.SisComercioContext>());

        public DbSet<Cidade> Cidade { get; set; }

        public DbSet<Endereco> Endereco { get; set; }

        public DbSet<Cliente> Cliente { get; set; }

        public DbSet<Pais> Pais { get; set; }

        public DbSet<Pessoa> Pessoa { get; set; }

        public DbSet<PessoaFisica> PessoasFisica { get; set; }

        public DbSet<PessoaJuridica> PessoasJuridica { get; set; }

        public DbSet<Telefone> Telefone { get; set; }

        public DbSet<TipoEndereco> TiposEndereco { get; set; }

        public DbSet<UF> UF { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

            modelBuilder.Entity<Pessoa>().ToTable("Pessoa");
            modelBuilder.Entity<PessoaFisica>().ToTable("PessoaFisica");
            modelBuilder.Entity<PessoaJuridica>().ToTable("PessoaJuridica");
            modelBuilder.Entity<Cliente>().ToTable("Clientes");

            base.OnModelCreating(modelBuilder);
        }
    }
}
